/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ipfms.stripes.util;


import java.util.Properties;
import com.google.inject.Singleton;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author fikri
 */
@Singleton
public class Configuration {
    
    public static final String CONF_FILE =  "/thv3.properties";

    private Properties props = new Properties();

	public Configuration(){
	    try {
	        props.load(Configuration.class.getResourceAsStream(CONF_FILE));               
	    } catch (Exception e) {
	    	props = null;
	    	throw new RuntimeException("SEVERE: Could not load configuration properties at " +
	    			CONF_FILE);
	    }
	}

	public String getProperty(String propName){
		if (props == null){
			throw new RuntimeException("SEVERE: Configuration was not successful loaded!");
		}

		return props.getProperty(propName);
	}

        public Map<String,String> getAllPropertiesWithValue() {
            Map<String, String> map = new HashMap<String, String>();
            Set<String> s = props.stringPropertyNames();

            for (Iterator<String> it = s.iterator(); it.hasNext();) {
                String string = it.next();
                String value = getProperty(string);
                map.put(string, value);
            }
            return map;
        }

        public void store(Properties prop) {
            try {
                prop.store(new FileOutputStream(new File(CONF_FILE)), null);
            } catch (Exception ex) {
                Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
}
